﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenAPI.CommonLib;

namespace TestProject
{
	/// <summary>
	/// 硬件信息测试
	/// </summary>
	public class DeviceInfo
	{
		/// <summary>
		/// 获取主板信息
		/// </summary>
		public void GetBoardInfo()
		{
			foreach (DictionaryEntry item in Environment.GetEnvironmentVariables())
			{
				System.Management.SelectQuery query = new System.Management.SelectQuery("select * from Win32_BaseBoard");
				ManagementObjectSearcher driverId = new ManagementObjectSearcher(query);
				ManagementObjectCollection.ManagementObjectEnumerator data = driverId.Get().GetEnumerator();
				data.MoveNext();
				ManagementBaseObject board = data.Current;
				Console.WriteLine("主板编号：" + board.GetPropertyValue("SerialNumber").ToString());
				Console.WriteLine("主板制造商：" + board.GetPropertyValue("Manufacturer").ToString());
				Console.WriteLine("主板型号：" + board.GetPropertyValue("Product").ToString());
			}
		}

		void GetDiskId()
		{
			ManagementObjectSearcher driverId = new ManagementObjectSearcher("select * from Win32_PhysicalMedia");
			string DiskId = "";
			foreach (var item in driverId.Get())
			{
				DiskId = item["SerialNumber"].ToString().Trim();
				break;
			}
			Console.WriteLine("硬盘编号：" + DiskId);
		}
		void GetDisk()
		{
			var disks = System.IO.Directory.GetLogicalDrives();
			foreach (var item in disks)
			{
				Console.WriteLine(item);
			}
			var diskInfo = System.IO.DriveInfo.GetDrives();
			for (int i = 0; i < diskInfo.Length; i++)
			{
				Console.WriteLine(diskInfo[i].DriveFormat);
				Console.WriteLine("总空间：" + diskInfo[i].TotalSize / 1024 / 1024 / 1024 + "G");
				Console.WriteLine("剩余空间：" + diskInfo[i].TotalFreeSpace / 1024 / 1024 / 1024 + "G");
				Console.WriteLine("已用空间：" + (diskInfo[i].TotalSize - diskInfo[i].TotalFreeSpace) / 1024 / 1024 / 1024 + "G");
			}
		}
		void PNDevice() 
		{
			ManagementObjectSearcher FlashDevice = new ManagementObjectSearcher("select * from Win32_VideoController");
			foreach (var item in FlashDevice.Get())
			{
				Console.WriteLine(item["name"].ToString());
				Console.WriteLine(item["PNPDeviceID"].ToString());
			}
		}

		void GetIp() 
		{
			var ipAddressList = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList;
			foreach (var item in ipAddressList)
			{
				Console.WriteLine(item);
			}
			//是否联网
			Console.WriteLine(System.Windows.Forms.SystemInformation.Network);
			Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.History));
			Console.WriteLine(Environment.UserName);
			Console.WriteLine(System.Security.Principal.WindowsAccountType.Guest);
			var p=(System.Security.Principal.WindowsPrincipal)System.Threading.Thread.CurrentPrincipal;
		}
	}
}
